<?php include("/includes/header.php") ?>
<?php include("/includes/sidebar.php") ?>
<?php $idfo = base64_decode($_GET[trim(base64_encode("id"), '=')]); ?>
<?php
	$gender = array('m' => 'Male', 'f' => 'Female');

	$sql = "SELECT * FROM front_office WHERE id = '".$idfo."'";
	$query = mysql_query($sql);
	$data = mysql_fetch_array($query);
	$data = validateData($data);
	extract($data);
	$data_agent = getAgent($idagent);

	// SELECTING TRAVEL AGEN
	// $sql_select_agent = "SELECT * FROM agent WHERE id = '".$idagent."'";
	// $query_select_agent = mysql_query($sql_select_agent);
	// $data_agent = mysql_fetch_array($query_select_agent);


	$sql_select_service_charge = "SELECT * FROM service_charge WHERE idfront_office = '".$idfo."'";
	$query_select_service_charge = mysql_query($sql_select_service_charge);

	// SELECTING ROOM INFORMATION
	$data_room = getRoom($idroom);

	// CALCULATE THE DATE BETWEEN CHECKOUT AND CHECKIN
	$diff = abs(strtotime($checkout) - strtotime($checkin));
	$days = floor($diff / (60*60*24));
	// $months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
	// $days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));

	// printf("%d years, %d months, %d days\n", $years, $months, $days);
?>

<style type="text/css">
	tbody tr:not(:first-child) td {
		border-top: none !important;
		/*border-bottom: none !important;*/
	}
	tbody tr:not(:last-child) td {
		border-bottom: 1px dotted #ccc !important;
		/*border-bottom: none !important;*/
	}
</style>

<div class="content row-fluid">
	<div class="span12 table-placer">
		<div class="alert alert-info"><h4>Occupier Info - <?php echo $nama; ?></h4></div>
		<div class="row-fluid index-pos-placer content">
			<div class="span12 tabbable">
				<ul id="myTab" class="nav nav-tabs">
					<li class="active"><a href="#detail1" data-toggle="tab">Occupier Info</a></li>
					<?php if ($banyak_orang > 1): ?>
					<li><a href="#detail2" data-toggle="tab">Other Guests</a></li>
					<li><a href="#detail3" data-toggle="tab">Service Charges</a></li>
					<?php endif ?>
				</ul>
				<div id="myTabContent" class="tab-content">
					<div class="tab-pane active" id="detail1">
						<div  class="row-fluid">
							<div class="span6">
								<fieldset>
									<dl>
										<dt>Name</dt>
										<dd><?php echo $nama; ?></dd>
										<dt>Place / Date of Birth</dt>
										<dd><?php echo $tempat_lahir; ?> / <?php echo date(  "F j, Y", strtotime( $tanggal_lahir ) ); ?></dd>
										<dt>Gender</dt>
										<dd><?php echo $gender[$jenis_kelamin]; ?></dd>
										<dt>Address</dt>
										<dd><?php echo $alamat; ?></dd>
										<dt>Occupancy</dt>
										<dd><?php echo $pekerjaan; ?></dd>
										<dt>Passport Number</dt>
										<dd><?php echo $passport; ?></dd>
										<dt>Email / Phone Number</dt>
										<dd><?php echo $email; ?> / <?php echo $telepon; ?></dd>
									</dl>
								</fieldset>
							</div>
							<div class="span6">
								<fieldset>
									<dl>
										<dt>Coming From - Going To</dt>
										<dd><?php echo $datang_dari; ?> - <?php echo $pergi_ke; ?></dd>
										<dt>Arrival Date - Departure Date</dt>
										<dd><?php echo date(  "F j, Y", strtotime( $tanggal_kedatangan ) ); ?> - <?php echo date(  "F j, Y", strtotime( $tanggal_keberangkatan ) ); ?></dd>
										<dt>Checkin Date - Checkout Date</dt>
										<dd><?php echo date(  "F j, Y", strtotime( $checkin ) ); ?> - <?php echo date(  "F j, Y", strtotime( $checkout ) ); ?> (<?php echo $days; echo ($days>1) ? " Days" : " Day" ; ?>)</dd>
										<dt>Agent</dt>
										<dd><?php echo (count($data_agent) > 1) ? "<a href='#' class='label label-info'>".$data_agent["nama"]."</a>" : "<span class='label'>Not Using Any Agent</span>" ; ?></dd>
										<dt>Stayed in</dt>
										<dd><?php echo $data_room["nama"]; ?></dd>
										<dt>Amount of People</dt>
										<dd><?php echo $banyak_orang; ?></dd>
									</dl>
								</fieldset>
							</div>
						</div>
					</div>
					<?php if ($banyak_orang > 1): ?>
					<div class="tab-pane" id="detail2">
					<?php
						$sql = "SELECT * FROM guests_details WHERE idfront_office = '".$idfo."'";
						$query = mysql_query($sql);
						// $banyak_guests = mysql_num_rows($query);
					?>
					<?php if (mysql_num_rows($query) < 1): ?>
						<div class="alert alert-info">
							<p>
								You haven't registered any details for the other guests. Please confirm their details.
								<button class="btn">Register Details</button>
							</p>
						</div>
					<?php else: ?>
						<div class="span12 tabbable tabs-right">
							<ul id="myTabDetails" class="nav nav-tabs">
					<?php
						for ($i=1; $i <= $banyak_orang-1; $i++) {
							$status_active = "";
							if ($i == 1) {
								$status_active = "active";
							}
					?>
								<li class="<?php echo $status_active; ?>">
									<a href="#person<?php echo $i; ?>" data-toggle="tab">Person <?php echo $i; ?> (CTRL + <?php echo $i; ?>)</a>
								</li>
					<?php
						}
					?>
							</ul>
							<div id="myTabContentDetails" class="tab-content">
					<?php
						$x = 1;
						while ($data_guests = mysql_fetch_array($query)) {
							$status_active = "";
							if ($x == 1) {
								$status_active = "active in";
							}
					?>
								<div class="tab-pane <?php echo $status_active; ?>" id="person<?php echo $x; ?>">
									<div  class="row-fluid">
										<div class="span6">
											<fieldset>
												<dl>
													<dt>Name</dt>
													<dd><?php echo $data_guests["nama"]; ?></dd>
													<dt>Occupation</dt>
													<dd><?php echo $data_guests["pekerjaan"]; ?></dd>
													<dt>Place / Date of Birth</dt>
													<dd><?php echo $data_guests["tempat_lahir"]; ?> / <?php echo date(  "F j, Y", strtotime( $data_guests["tanggal_lahir"] ) ); ?></dd>
													<dt>Gender</dt>
													<dd><?php echo $gender[$data_guests["jenis_kelamin"]]; ?></dd>
												</dl>
											</fieldset>
										</div>
										<div class="span6">
											<fieldset>
												<dl>
													<dt>Email Address</dt>
													<dd><?php echo $data_guests["email"]; ?></dd>
													<dt>Phone Number</dt>
													<dd><?php echo $data_guests["telepon"]; ?></dd>
													<dt>Passport Number</dt>
													<dd><?php echo $data_guests["passport"]; ?></dd>
													<dt>Address</dt>
													<dd><?php echo $data_guests["alamat"]; ?></dd>
												</dl>
											</fieldset>
										</div>
									</div>
								</div>
					<?php
							$x++;
						}
					?>
							</div>
						</div>
					<?php endif ?>
					</div>
					<?php endif ?>
					<div class="tab-pane" id="detail3">
						<div  class="row-fluid">
							<table class="table table-bordered">
								<thead>
									<tr>
										<th class="al_center" width="50%">Description</th>
										<th class="al_center" width="10%">Price</th>
										<th class="al_center" width="10%">Guests</th>
										<th class="al_center" width="10%">Quantity</th>
										<th class="al_center" width="20%">Amount</th>
									</tr>
								</thead>
								<tbody id="invoice">
									<?php
										if (mysql_num_rows($query) > 0) {
											$grand_total = 0;
											while ($data_service_charge = mysql_fetch_array($query_select_service_charge)) {
												$grand_total += ($data_service_charge["jumlah"]*$data_service_charge["harga"]);
									?>
									<tr>
										<td class="al_left"><?php echo $data_service_charge["nama"]; ?></td>
										<td class="al_right currency" valign="middle"><?php echo $data_service_charge["harga"]; ?></td>
										<td class="al_center" valign="middle">-</td>
										<td class="al_center" valign="middle"><?php echo $data_service_charge["jumlah"]; ?></td>
										<td class="al_right currency amount_inv" valign="middle"><?php echo ($data_service_charge["jumlah"]*$data_service_charge["harga"]); ?></td>
									</tr>
									<?php
											}
										}
									?>
								</tbody>
							</table>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

<div class="footer">
</div>

<?php include("/includes/footer.php") ?>

<script type="text/javascript">
	$(document).ready(function() {
		var elPop;
		$('.index-pos').popover();
		$('.table-placer').on('click', '.index-pos', function(event) {
			event.preventDefault();
			/* Act on the event */
			// elPop = $(this);
			// $(".index-pos").popover("hide");
		});
		// $('.index-pos').on('hidden.bs.popover', function () {
		// 	elPop.popover("show");
		// })
	});
</script>